/**
 * 
 */
package t4j.strings;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import t4j.net.mindview.util.TextFile;

/*! Here's a block of text to use as input to
the regular expression matcher. Note that we'll
first extract the block of text by looking for
the special delimiters, then process the
extracted block. !*/

public class TheReplacements {

	public static void main(String[] args) {
		String s = TextFile.read("src\\t4j\\strings\\TheReplacements.java");
		
		Matcher mInput = Pattern.compile("/\\*!(.*)!\\*/", Pattern.DOTALL).matcher(s);
		
		if(mInput.find()){
			s = mInput.group(1);
//			System.out.println(s);
		}
		
		s = s.replaceAll(" {2,}", " ");
		
//		System.out.println(s);
	
		s = s.replaceAll("(?m)^ +", "");
		
		System.out.println(s);
		
		s = s.replaceFirst("[aeiou]", "(VOWEL1)");//只替换第一个匹配的
		
		System.out.println(s);
		
		StringBuffer sbuf = new StringBuffer();
		
		Pattern p = Pattern.compile("[aeiou]");
		
		Matcher m = p.matcher(s);
		
		while(m.find()){
			
			System.out.println("---------"+m.group() +"---------------------");
			
			m.appendReplacement(sbuf, m.group().toUpperCase());//执行渐进式的替换
			
			System.out.println(sbuf);
			
			//break;
			
		}
		
		m.appendTail(sbuf);//将字符串余下的部分复制到sbuf
		
		System.out.println(sbuf);
	}
}
